package com.algo.ext;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

/**
 * 执行时机是在所有BeanDefinition信息加载完成，尚未完成单例Bean实例化之前
 * 调用链路为：
 *      创建 AnnotationConfigApplicationContext初始化 -> refresh -> invokeBeanFactoryPostProcessors
 */
@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        int beanDefinitionCount = beanFactory.getBeanDefinitionCount();
        System.out.println("MyBeanFactoryPostProcessor: 容器中beanDefinitionCount为：" + beanDefinitionCount);
    }

}
